<div class="comments_wrapper">
    <div class="comments_title"><?php echo __('Post a Comment') ?></div>
    <div class="comment_textarea">
        <form onsubmit="return postsubmit()" target="comment_post" id="comment_form" action="<?php echo url_for('comments/post?model_id='.$model_id) ?>" method="post">
            <textarea id="comment_text" name="comment_text"></textarea>
        </form>
        <div class="post_comment_wrap">
            <iframe class="comment_post" name="comment_post"></iframe>
            <div class="dos_button">
                <a href="javascript:void(0)" onclick="$('#comment_form').submit();"><?php echo __('Post Comment') ?></a>
            </div>
            <div class="clear"></div>
        </div>
    </div>
    <?php if($count > 0){ ?>
    <div class="comments_sort">
        <div><?php echo __('Sort By:') ?></div>
        <div class="mleft"><a class="selected" href="javascript:;"><?php echo __('Post Date') ?></a></div>
        <div class="mleft"><a href="javascript:;"><?php echo __('Sender Name') ?></a></div>
        <div class="mleft"><a href="javascript:;"><?php echo __('Sender Rating') ?></a></div>
    </div>
    <div class="clear"></div>
    <?php } ?>
    <?php foreach($comments as $one){ ?>
        <?php include_component('comments', 'block', array('comment'=>$one)) ?>
    <?php } ?>
</div>
<script>
    function postsubmit(){
        if($('#comment_text').val().trim() == '') return false;
        return true;
    }
</script>
<script>
    $('.comment_rating').raty({
        path: '<?php echo public_path('images/raty_darker/', true) ?>'
        ,size: 22
        ,start: function() {
            return $(this).attr('data-rating');
        }
        ,click: function(rate){
            _rate_elem = this;
            _did = $(this).attr('data-did');
            $.cookie('rated_comment_'+_did, true, '/');
            $.ajax({
                url: "<?php echo url_for('comments/rate') ?>?rate="+rate+"&did="+_did,
                context: document.body
            }).done(function(data) { 
                $(_rate_elem).raty('start', data);
                $(_rate_elem).raty('readOnly', true);
            });
        }
    });

</script>